from django import forms
from bazy.models import *
import datetime
class LoginForm(forms.Form):
	username =forms.CharField(max_length=200,required=True, label='Username')
	password = forms.CharField( widget=forms.PasswordInput(render_value=False), label="Password" )
	
class AddUserForm(forms.Form):
	
	name = forms.CharField(max_length=100,required=True, label='Name')
	lastname = forms.CharField(max_length=100,required=True, label='Lastname')
	username =forms.CharField(max_length=100,required=True, label='Username')
	password = forms.CharField( widget=forms.PasswordInput(render_value=False), label="Password" )
	rePassword = forms.CharField( widget=forms.PasswordInput(render_value=False), label="Retype password" )
	address= forms.CharField(max_length=100,required=True, label='Address')
	cardNumber=forms.CharField(max_length=10,required=True, label='Card number')
	phoneNumber=forms.CharField(max_length=9,required=True, label='Phone number')
	EXTRA_CHOICES = [('0', 'Administrative'),
					 ('1', 'Steward'),
					 ]
	privilage = forms.CharField( widget=forms.Select(choices=EXTRA_CHOICES),label='Privilage')

def getUserSelect():
	users=list();
	objects= User.objects.all()
	for user in objects:
		users.append((user.id,user.username))
	return users

def getOffenseSelect():
	offenses=list();
	objects= OffenseType.objects.all()
	for offense in objects:
		offenses.append((offense.id,offense.name))
	return offenses

def getHooligansSelect():
	hools=list();
	objects= Hooligan.objects.all()
	for hooligan in objects:
		hools.append((hooligan.id,hooligan.name+' '+hooligan.lastname))
	return hools

def getEventSelect():
	events=list();
	objects= Event.objects.all()
	for event in objects:
		events.append((event.id,event.offenseType.name+'- '+event.date.strftime('%Y-%m-%d %H:%M:%S')))
	return events

class CreateHooliganForm(forms.Form):
	name= forms.CharField(max_length=100)
	lastname= forms.CharField(max_length=100)
	
	user =forms.CharField( widget=forms.Select(choices=getUserSelect()))
   # date = forms.DateTimeField();
	photo  = forms.FileField()

class CreateEventForm(forms.Form):
	user =forms.ChoiceField(choices=getUserSelect())
	offenseType=forms.ChoiceField(choices=getOffenseSelect())
	hooligans= forms.MultipleChoiceField( required=False, choices=getHooligansSelect())
	coordinatesWidth= forms.CharField(max_length=100)
	coordinatesHeight= forms.CharField(max_length=100)
	date = forms.DateTimeField(initial=datetime.datetime.now());

	def __init__(self, *args, **kwargs):
		super(CreateEventForm, self).__init__(*args, **kwargs)
		self.fields['offenseType'].choices = getOffenseSelect() 
		self.fields['user'].choices = getUserSelect()
		self.fields['hooligans'].choices = getHooligansSelect()

class AddHooliganToEvent(forms.Form):
	event_id= forms.CharField(widget=forms.HiddenInput())
	hooligans= forms.MultipleChoiceField( required=False, choices=getHooligansSelect())
	def __init__(self, *args, **kwargs):
		super(AddHooliganToEvent, self).__init__(*args, **kwargs)
		self.fields['hooligans'].choices =getHooligansSelect()
		
class AddEventToHooligan(forms.Form):
	event_id= forms.ChoiceField(choices=getEventSelect())


	def __init__(self, *args, **kwargs):
		super(AddEventToHooligan, self).__init__(*args, **kwargs)
		self.fields['event_id'].choices =getEventSelect()  

class CreateOffenseTypeForm(forms.Form):
	name= forms.CharField()
	harmfulness= forms.CharField(widget=forms.Select(choices=[('0', 'slabo'),('1', 'troche mocniej'),('2', 'do piachu')]))
	overview= forms.CharField(widget=forms.Textarea)


#class OffenseType(models.Model):
#	name= models.CharField(max_length=100)
#	harmfulness= models.IntegerField()
#	overview= models.CharField(max_length=300)
